﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Philip Stears 
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@connectbasic.net.
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

namespace ConnectBasic.ObjectModel
{
    using System;
    using System.Diagnostics;

    /// <summary>
    /// Represents a type which hasn't been bound to a runtime representation.
    /// </summary>
    [DebuggerDisplay("Type {Name}")]
    public class UnboundType
    {
        private readonly static UnboundType sVoid = new UnboundType("Void");
        private readonly static UnboundType sVariant = new UnboundType("Variant");
        private readonly string mTypeName;
        private readonly int mDimensions;

        /// <summary>
        /// Initializes a new instance of the <see cref="UnboundType"/> class.
        /// </summary>
        /// <param name="name">The name of the type.</param>
        public UnboundType(string name)
        {
            mTypeName = name;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UnboundType"/> class.
        /// </summary>
        /// <param name="name">The name of the type.</param>
        /// <param name="arrayDimensions">The number of dimensions in the array.</param>
        public UnboundType(string name, int arrayDimensions)
            : this(name)
        {
            if (arrayDimensions <= 0) throw new ArgumentOutOfRangeException("arrayDimensions");
            mDimensions = arrayDimensions;
        }

        /// <summary>
        /// Gets the "void" type.
        /// </summary>
        public static UnboundType Void
        {
            get { return sVoid; }
        }

        /// <summary>
        /// Gets the "variant" type.
        /// </summary>
        public static UnboundType Variant
        {
            get { return sVariant; }
        }

        /// <summary>
        /// Determines whether the type is the "void" type.
        /// </summary>
        /// <returns></returns>
        public bool IsVoid
        {
            get { return this == UnboundType.Void; }
        }

        /// <summary>
        /// Gets the type name.
        /// </summary>
        public string Name
        {
            get { return mTypeName; }
        }

        /// <summary>
        /// Determines whether the type is an array type.
        /// </summary>
        public bool IsArray
        {
            get { return mDimensions > 0; }
        }

        /// <summary>
        /// If the type is an array type, determines the total number of dimensions in the array.
        /// </summary>
        public int ArrayDimensions
        {
            get { return mDimensions; }
        }
    }
}
